<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择日期" v-decorator="['salaryTime']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['auditGrade']" :trigger-change="true" dictCode="audit_grade" placeholder="请选择部门" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['name']" placeholder="请输入姓名"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="合同工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['contractSalary']" placeholder="请输入合同工资" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="税前工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['salaryBeforeTax']" placeholder="请输入税前工资" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="岗位绩效及加班费" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['postPerformance']" placeholder="请输入岗位绩效及加班费" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="保密补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['confidentialAssistance']" placeholder="请输入保密补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="交通及通讯" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['trafficCommunication']" placeholder="请输入交通及通讯" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="全勤奖" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['attendanceBonus']" placeholder="请输入全勤奖" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="BM补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['bmAllowance']" placeholder="请输入BM补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="管理津贴" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['managementAllowance']" placeholder="请输入管理津贴" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="奖励金" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['incentivePayment']" placeholder="请输入奖励金" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="电脑补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['computerAllowance']" placeholder="请输入电脑补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="出差补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['travelAllowance']" placeholder="请输入出差补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="误餐补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['mealGrants']" placeholder="请输入误餐补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="防暑降温补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['heatstrokePrevention']" placeholder="请输入防暑降温补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="冬季取暖补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['heatingAllowance']" placeholder="请输入冬季取暖补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="独生子女补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['oneChildAllowance']" placeholder="请输入独生子女补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="托儿补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['childcareSubsidies']" placeholder="请输入托儿补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="商业保险补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['commercialInsuranceSubsidy']" placeholder="请输入商业保险补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="请假" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['askForLeave']" placeholder="请输入请假" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="扣款" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['deductMoney']" placeholder="请输入扣款" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="税前总计" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['beforeTotal']" placeholder="请输入税前总计" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="养老" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['endowmentInsurance']" placeholder="请输入养老" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="失业" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['unemploymentInsurance']" placeholder="请输入失业" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="医疗" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['medicalInsurance']" placeholder="请输入医疗" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="住房公积金" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['housingProvidentFund']" placeholder="请输入住房公积金" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="社保年检补缴" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['socialSecurityCheck']" placeholder="请输入社保年检补缴" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="小计" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['subtotal']" placeholder="请输入小计" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="个税" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['payTaxes']" placeholder="请输入个税" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="其他扣款" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['otherDeductMoney']" placeholder="请输入其他扣款" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="总计" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['total']" placeholder="请输入总计" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="代发工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['payrollCredit']" placeholder="请输入代发工资" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="代发补助" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['payrollSubsidy']" placeholder="请输入代发补助" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HfWageSalaryCountForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/wage/hfWageSalaryCount/add",
          edit: "/wage/hfWageSalaryCount/edit",
          queryById: "/wage/hfWageSalaryCount/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'salaryTime','auditGrade','name','contractSalary','salaryBeforeTax','postPerformance','confidentialAssistance','trafficCommunication','attendanceBonus','bmAllowance','managementAllowance','incentivePayment','computerAllowance','travelAllowance','mealGrants','heatstrokePrevention','heatingAllowance','oneChildAllowance','childcareSubsidies','commercialInsuranceSubsidy','askForLeave','deductMoney','beforeTotal','endowmentInsurance','unemploymentInsurance','medicalInsurance','housingProvidentFund','socialSecurityCheck','subtotal','payTaxes','otherDeductMoney','total','payrollCredit','payrollSubsidy'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'salaryTime','auditGrade','name','contractSalary','salaryBeforeTax','postPerformance','confidentialAssistance','trafficCommunication','attendanceBonus','bmAllowance','managementAllowance','incentivePayment','computerAllowance','travelAllowance','mealGrants','heatstrokePrevention','heatingAllowance','oneChildAllowance','childcareSubsidies','commercialInsuranceSubsidy','askForLeave','deductMoney','beforeTotal','endowmentInsurance','unemploymentInsurance','medicalInsurance','housingProvidentFund','socialSecurityCheck','subtotal','payTaxes','otherDeductMoney','total','payrollCredit','payrollSubsidy'))
      },
    }
  }
</script>